<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>新增留言</title>
    <link href="${basePath }/static/plugins/layui/css/layui.css" rel="stylesheet"/>
    <link href="${basePath}/static/plugins/email-auto-complete/emailAutoComplete.css" rel="stylesheet">
</head>
<body>
<form id="comment-form" class="layui-form" action="javascript:;" style="margin: 24px 48px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <div class="parentCls">
                <input type="text" name="email" placeholder="请输入邮箱" class="layui-input inputElem">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="phone" placeholder="请输入手机" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">置顶</label>
        <div class="layui-input-block">
            <input type="checkbox" name="top" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">留言</label>
        <div class="layui-input-block">
            <textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="comment-form">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    form.render();
    form.on('submit(comment-form)', function(data){
        var reqData = data.field;
        console.log(data);
        $.ajax({
            url: '${basePath}/admin/comment/insert',
            type: 'post',
            dataType: 'json',
            data: reqData,
            success: function(resp){
                if(resp.code==10000){
                    layer.msg('新增成功',{
                        time: 1000
                    }, function(){
                        $('#comment-form button[type="reset"]').trigger('click');
                    })
                }
            }
        })
        return false;
    });
</script>
</body>
</html>
